package cn.fulong.sso.client.utils;



import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

/**
 * @Version 1.0
 * @Author: 云树
 * @Description:
 * @Date: 2019/2/26
 * @Modify 云树
 * @ModifyDate 2019/2/26
 * @since 1.0
 */
public class StringSelfUtil {
    public static final String EMPTY = "";
    public static final String SPLIT_COMMA = "\\s*,\\s*";

    public static String trim(String str) {
        return str == null ? null : str.trim();
    }

    public static boolean isBlank(String str) {
        return str == null || str.trim().length() <= 0;
    }

    public static boolean isNotBlank(String str) {
        return !isBlank(str);
    }


    public static boolean equals(String cs1, String cs2) {
        if (cs1 == cs2) {
            return true;
        }
        if (cs1 != null && cs2 != null) {
            return cs1.equals(cs2);
        }
        return false;
    }

    public static boolean equalsIgnoreCase(String cs1, String cs2) {
        if (cs1 == cs2) {
            return true;
        }
        if (cs1 != null && cs2 != null) {
            return cs1.equalsIgnoreCase(cs2);
        }
        return false;
    }

    public static boolean equalsIgnoreTrimCase(String cs1, String cs2) {
        if (cs1 == cs2) {
            return true;
        }
        if (cs1 != null && cs2 != null) {
            return cs1.trim().equalsIgnoreCase(cs2.trim());
        }
        return false;

    }

    public static boolean isNumeric(String cs) {
        if (isBlank(cs)) {
            return false;
        }
        int sz = cs.length();
        for (int i = 0; i < sz; ++i) {
            if (!Character.isDigit(cs.charAt(i))) {
                return false;
            }
        }
        return true;
    }


    public static Set<String> split(String str, String split) {
        if (isBlank(str)) {
            return Collections.EMPTY_SET;
        }
        return new HashSet<>(Arrays.asList(str.split(split)));
    }
    public static boolean areNotEmpty(String... values) {
        if (values == null) {
            return false;
        }
        int len = values.length;
        if (len < 1) {
            return false;
        }
        for (int i = 0; i < len; i++) {
            String value = values[i];
            if (StringSelfUtil.isBlank(value)) {
                return false;
            }
        }
        return true;
    }

}
